var app = app || {};
app.soccer = {};
app.soccer.ballX = 145;
app.soccer.ballY = 180;
app.soccer.startX = 0;
app.soccer.startY = 0;
app.soccer.endX = 0;
app.soccer.endY = 0;

(function($) {
	$(function() {
		var $ball = $('#ball');
		$ball.bind('touchstart click', tStart);
		$ball.bind('touchmove', tMove);
		$ball.bind('touchend', tEnd);

		var $body = $('body');
		$body.bind('touchmove', function(e) {
			e.preventDefault();
		});
	});

	function tStart(e) {
		var touch = event.touches[0];
		var soccer = app.soccer;
		soccer.startX = touch.pageX;
		soccer.startY = touch.pageY;
	}

	function tMove(e) {
		var touch = event.touches[0];
		var soccer = app.soccer;
		soccer.endX = touch.pageX;
		soccer.endY = touch.pageY;
	}
	function tEnd() {
		var soccer = app.soccer;
		var diffX = soccer.endX - soccer.startX;
		var diffY = soccer.endY - soccer.startY;

		soccer.ballX = soccer.ballX + diffX;
		soccer.ballY = soccer.ballY + diffY;
		
		//$('#debug').html(soccer.ballX + ", " + soccer.ballY);
		
		var $ball = $('#ball');
		$ball.css('left', soccer.ballX);
		$ball.css('top', soccer.ballY);
	}
})(jQuery);